package com.nuo.modules.signRecord.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nuo.common.excel.po.ExportListPo;
import com.nuo.common.excel.service.ExcelService;
import com.nuo.common.utils.PageUtils;
import com.nuo.common.utils.R;
import com.nuo.modules.signRecord.entity.SignRecordEntity;
import com.nuo.modules.signRecord.po.SignRecordPO;
import com.nuo.modules.signRecord.service.SignRecordService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 *
 *
 * @author hbc
 * @email hbc@gmail.com
 * @date 2022-11-25 14:36:11
 */
@RestController
@RequestMapping("signRecord/signrecord")
public class SignRecordController {
    @Autowired
    private SignRecordService signRecordService;

    @Autowired
    ExcelService excelService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("signRecord:signrecord:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = signRecordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("signRecord:signrecord:info")
    public R info(@PathVariable("id") Long id){
		SignRecordEntity signRecord = signRecordService.getById(id);

        return R.ok().put("signRecord", signRecord);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("signRecord:signrecord:save")
    public R save(@RequestBody SignRecordEntity signRecord){
		signRecordService.save(signRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("signRecord:signrecord:update")
    public R update(@RequestBody SignRecordEntity signRecord){
		signRecordService.updateById(signRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("signRecord:signrecord:delete")
    public R delete(@RequestBody Long[] ids){
		signRecordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 导出签到信息
     */
    @PostMapping("/exportList")
    public R exportList(@RequestBody SignRecordPO po){

        ExportListPo<SignRecordEntity> excel=new ExportListPo<>();
        List<SignRecordEntity> list = signRecordService.list(new LambdaQueryWrapper<SignRecordEntity>().like(StringUtils.isNotBlank(po.getDateTime()),SignRecordEntity::getCreateTime, po.getDateTime()));

        // ces
        excel.setList(list);
        return excelService.exportList(excel,SignRecordEntity.class);
    }


}
